<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<style>
	.box .box-header .box-title small a {
		cursor: pointer;
		padding: 0 5px;
		border-right: 1px solid #999;
	}
	.box .box-header .box-title small a:last-child {
		border-right: none;
	}
	.box .box-header .box-title small a.text-default {
		color: #999;
	}

	.box .box-header .box-title small a.active {
		font-weight: bolder;
		text-decoration: underline;
	}
</style>

<div class="box box-primary">
	<div class="box-header with-border">
		<h3 class="box-title">
			Job List
			<small>
				<a class="no-select text-{{getStateClass(state.key)}}" ng-class="{active: (tableScope.search || '').toUpperCase() === state.key}"
					  ng-repeat="state in jobStateList" ng-click="fillSearch(state.key)">
					{{state.key}}: {{state.value}}
				</a>
			</small>
			<span ng-show="!jobList._done || isSorting" class="fa fa-refresh fa-spin no-animate"></span>
		</h3>
	</div>
	<div class="box-body">
		<div id="jobList" sort-table="jobList" is-sorting="isSorting" search-path-list="searchPathList" scope="tableScope" class="table-responsive">
			<table class="table table-bordered">
				<thead>
					<tr>
						<th sortpath="tags.jobId">Job ID</th>
						<th sortpath="tags.jobName">Job Name</th>
						<th sortpath="currentState">Status</th>
						<th sortpath="tags.user" width="10">User</th>
						<th sortpath="tags.queue">Queue</th>
						<th sortpath="submissionTime">Submission Time</th>
						<th sortpath="startTime">Start Time</th>
						<th sortpath="endTime">End Time</th>
						<th sortpath="durationTime">Duration</th>
						<th sortpath="numTotalMaps">Map Tasks</th>
						<th sortpath="numTotalReduces">Reduce Tasks</th>
						<th sortpath="runningContainers">Containers</th>
					</tr>
				</thead>
				<tbody>
					<tr ng-repeat="item in jobList">
						<td>
							<a ui-sref="jpmDetail({siteId: site, jobId: item.tags.jobId})" target="_blank">{{item.tags.jobId}}</a>
						</td>
						<td>{{item.tags.jobName}}</td>
						<td class="text-center">
							<span class="label label-sm label-{{getStateClass(item.currentState)}}">
								{{item.currentState}}
							</span>
						</td>
						<td>{{item.tags.user}}</td>
						<td>{{item.tags.queue}}</td>
						<td>{{Time.format(item.submissionTime)}}</td>
						<td>{{Time.format(item.startTime)}}</td>
						<td>{{Time.format(item.endTime)}}</td>
						<td>{{Time.diffStr(item.durationTime)}}</td>
						<td>{{item.numTotalMaps}}</td>
						<td>{{item.numTotalReduces}}</td>
						<td>{{item.runningContainers || "-"}}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>

<div class="box box-primary">
	<div class="box-header with-border">
		<h3 class="box-title">
			Running Metrics
		</h3>
	</div>
	<div class="box-body no-padding">
		<div class="row border-split">
			<div class="col-sm-12 col-md-6">
				<div class="jpm-chart">
					<h3 class="text-center">Number of Running Jobs</h3>
					<div chart class="jpm-chart-container" series="runningTrendSeries" option="chartLeftOption"></div>
				</div>
			</div>
			<div class="col-sm-12 col-md-6">
				<div class="jpm-chart">
					<h3 class="text-center">Running Containers</h3>
					<div chart class="jpm-chart-container" series="runningContainersSeries" option="chartRightOption"></div>
				</div>
			</div>
		</div>
		<div class="row border-split">
			<div class="col-sm-12 col-md-6">
				<div class="jpm-chart">
					<h3 class="text-center">Allocated vCores</h3>
					<div chart class="jpm-chart-container" series="allocatedvcoresSeries" option="chartLeftOption"></div>
				</div>
			</div>
			<div class="col-sm-12 col-md-6">
				<div class="jpm-chart">
					<h3 class="text-center">Allocated Memory (GB)</h3>
					<div chart class="jpm-chart-container" series="allocatedMBSeries" option="allocatedMBOption"></div>
				</div>
			</div>
		</div>
	</div>
</div>
